package base.thread;


public class JoinTest extends Thread{
	static int result = 0;
	
	public static void main(String[] args) throws Exception{
		System.out.println("主线程执行");
		Thread thread=new JoinTest();
		long start=System.currentTimeMillis();
		thread.start();
		System.out.println(result);
		thread.join(2000);
		thread.interrupt();
		long end=System.currentTimeMillis();
		System.out.println((end-start)+"毫秒后："+result);
	}
	
	public void run(){
		System.out.println(this.getName()+"计算开始");
		try {
			Thread.sleep(4000);
		} catch (InterruptedException e) {
			e.printStackTrace();
			System.out.println("线程被中断");
//			return;
		}
		result=(int)(Math.random()*1000);
		System.out.println(this.getName()+"计算结束");
	}
}
